home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 122_01 / pistol.c < prev    next >
Text File  |  1984-03-05  |  4KB  |  188 lines

  1. /*********************************************************/
  2. /*                             */
  3. /* PISTOL-Portably Implemented Stack Oriented Language     */
  4. /*            Version 2.0             */
  5. /* (C) 1983 by    Ernest E. Bergmann             */
  6. /*        Physics, Building #16             */
  7. /*        Lehigh Univerisity             */
  8. /*        Bethlehem, Pa. 18015             */
  9. /*                             */
  10. /* Permission is hereby granted for all reproduction and */
  11. /* distribution of this material provided this notice is */
  12. /* included.                         */
  13. /*                             */
  14. /*********************************************************/
  15.  
  16. /* main PISTOL v2.0 module for BDS 'C' v1.45a */
  17. /* September 5, 1982 */
  18. #include "bdscio.h"
  19. #include "pistol.h"
  20.  
  21. /* CONSTANTS:
  22.     ram[..rammin-1]=future constants
  23.     ram[-21]=MININT
  24.     ram[-20]=MAXLINNO
  25.     ram[-19]=CHKLMT
  26.     ram[-18]=RAMMIN
  27.     ram[-17]=STRINGSMIN
  28.     ram[-16]=STRINGSMAX
  29.     ram[-15]=VBASE
  30.     ram[-14]=VSIZE
  31.     ram[-13]=CSIZE
  32.     ram[-12]=LSIZE
  33.     ram[-11]=RSIZE
  34.     ram[-10]=SSIZE
  35.     ram[-9]=LINEBUF
  36.     ram[-8]=COMPBUF
  37.     ram[-7]=RAMMAX
  38.     ram[-6]=MAXORD
  39.     ram[-5]=MAXINT
  40.     ram[-4]=VERSION
  41.     ram[-3]=NEWLINE
  42.     ram[-2]=READ PROTECTION BOOLEAN
  43.     ram[-1]=WRITE PROTECTION BOOLEAN
  44. VARIABLES:
  45.     ram[0]=RADIX
  46.     ram[1]=.C
  47.     ram[2]=.D
  48.     ram[3]=CURRENT END OF STRINGS
  49.     ram[4]=OLD END OF STRINGS
  50.     ram[5]=CURRENT
  51.     ram[6]=PREV(VFIND)
  52.     ram[7]=INPUT FILE
  53.     ram[8]=LIST OUT BOOLEAN
  54.     ram[9]=ECHO OUT BOOLEAN
  55.     ram[10]=CONSOLE OUT BOOLEAN
  56.     ram[11]=NEXTCHAR POINTER
  57.     ram[12]=LINELENGTH
  58.     ram[13]=RAISE BOOLEAN lc -> UC
  59.     ram[14]=HEAD OF TOKEN IN LINE
  60.     ram[15]=TRACE BOOLEAN AND LEVEL
  61.     ram[16]=COMPILE END PATCH
  62.     ram[17]=TERMINAL PAGE LENGTH
  63.     ram[18]=#LINE OUTPUT TO CONSOLE
  64.     ram[19]=TERMINAL WIDTH
  65.     ram[20]=COLUMN
  66.     ram[21]=ENDCASE PATCH ADDRESS
  67.     ram[22]=TRACE PATCH ADDRESS
  68.     ram[23]=TABSIZE
  69.     ram[24]=#GETLINE PATCH ADDRESS
  70.     ram[25]=FILE STATUS FOR LDFIL
  71.     ram[26]=FILE STATUS FOR EDIN
  72.     ram[27]=FILE STATUS FOR EDOUT
  73.     ram[28]=^ VSTACK
  74.     ram[29]=^PISTOL<
  75.     ram[30]=NIL,TERMINATES VLIST
  76.     ram[31]=SESSION DONE BOOLEAN
  77.     ram[32]=PROMPT PATCH ADDRESS
  78.     ram[33]=CONVERSION PATCH
  79.     ram[34]=ABORT PATCH
  80.     ram[35..VBASE+1]=FUTURE VARIABLES EXPANSION
  81.     ram[VBASE..VBASE+VSIZE]=VSTACK
  82. */
  83.  
  84. main()
  85. {
  86. /*??? doc the uses of ram[-20..?] */
  87.     init();    /*contains penter and fills farray */
  88.     setjmp(jbuf);    /* initialize return point */
  89.     /*reseting stacks returns i/o to tty: produces signon*/
  90.     ip=&ram;    /*so ram[ip] is in range*/
  91.     ram[15].in=ram[7].in=ram[31].in=FALS;
  92.     ram[28].pw=&ram[VBASE];
  93.     ram[5].pw=ram[VBASE].pw=&ram[29];
  94.     stkptr=cptr=lptr=0;
  95.     rptr=-1;
  96.     strings[1]='\0';
  97.     ram[10].in=TRU;
  98.     if (listname[0]=='\0') ram[8].in=FALS;
  99.     /*turns off listing if no listfile is open*/
  100.     message(id);
  101.     /* ifcr */
  102.     if (ram[20].in) carret();
  103.     if (ram[34].pw) {instr=ram[34].un;interpret();}
  104.     /* user supplied supplement to ABORT */
  105.     goto L99;
  106.     do{    ram[1].pw=&ram[COMPBUF];
  107.         do compline();
  108.          while(strings[1]);
  109.         compile(PSEMICOLON);
  110.         if(ram[16].pw) {instr=ram[16].un;interpret();}
  111.         if(ram[10].in&&(!ram[7].in||ram[9].in))
  112.             ram[20].in=ram[18].in=FALS;
  113.         instr=&ram[COMPBUF];
  114.         interpret();
  115.  
  116. L99:        ram[3].pc=ram[4].pc;
  117.     }
  118.     while( !ram[31].in );
  119.     
  120.     printf("\nPISTOL NORMAL EXIT\n");
  121.     if(ram[8].in) fprintf(list,"\nPISTOL NORMAL EXIT\n");
  122.     if(listname[0]) closout(list);
  123.     if(namout[0]) closout(edout);
  124.  
  125.     exit(); /*files need to be flushed and closed */
  126. }
  127.  
  128. closout(iobuf)
  129. char *iobuf;
  130. {    putc(CPMEOF,iobuf);
  131.     fflush(iobuf); fclose(iobuf);
  132. }
  133.  
  134. abort()
  135. { longjmp(jbuf); }
  136.  
  137.  
  138. compline()
  139. {/* static int inf,*pad; */
  140. inf=ram[7].in;
  141. if((!inf)||ram[9].in) prompt();
  142. if((inf>0)&&(inf<MAXLINNO))
  143.     {push(inf);
  144.     instr=ram[24].un;
  145.     interpret();
  146.     ram[7].in++;
  147.     }
  148. else getline();
  149. ignrblnks();
  150. while(*ram[11].pc != NEWLINE)
  151.     {ram[14].pc=ram[11].pc;
  152. intoken();
  153. push(ram[3].pc);
  154. find(); pad=pop();
  155.     if(pad) {instr=pad-1;interpret();}
  156.     else    {if(convert(ram[3].in,ram[0].in,&val))
  157.             {compile(LIT);compile(val);}
  158.         else    {if(Pc=ram[3].pc+1,*Pc=='\'')
  159.                 {pad=slit();compile(STRLIT);
  160.                 compile(pad);}
  161.             else if(*Pc=='"')
  162.                 {pad=longstring();
  163.                 compile(STRLIT);compile(pad);}
  164.             else if(ram[33].in)
  165.                 {instr=ram[33].un;interpret();}
  166.             else{/*token couldn't be deciphered*/
  167.                 ram[10].in=TRU;
  168.                 if(ram[7].in&&(!ram[9].in))
  169.                 {if(ram[20].in) carret();
  170.                  message(&strings[LINEBUF]);
  171.                 }
  172.                 message(ram[3].in);
  173.                 printf(" ?\n");
  174.                 if(ram[8].in)
  175.                     fprintf(list," ?\n");
  176.                 abort();
  177.                 }
  178.             }
  179.         }
  180.     ignrblnks();
  181.     }
  182. }
  183. t()
  184. { longjmp(jbuf); }
  185.  
  186.  
  187. compline()
  188. {/* sta